home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / graphics / 3dvect37.zip / MORE.INC < prev    next >
Text File  |  1994-06-22  |  14KB  |  405 lines

  1. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  2. ;
  3. ; Filename     : More.inc
  4. ; Included from: 3D1.ASM, 3D2.ASM, 3D3.ASM
  5. ; Description  : Irq palette fading routines
  6. ;
  7. ; Written by: John McCarthy
  8. ;             1316 Redwood Lane
  9. ;             Pickering, Ontario.
  10. ;             Canada, Earth, Milky Way (for those out-of-towners)
  11. ;             L1X 1C5
  12. ;
  13. ; Internet/Usenet:  BRIAN.MCCARTHY@CANREM.COM
  14. ;         Fidonet:  Brian McCarthy 1:229/15
  15. ;   RIME/Relaynet: ->CRS
  16. ;
  17. ; Home phone, (905) 831-1944, don't call at 2 am eh!
  18. ;
  19. ; John Mccarthy would really love to work for a company programming Robots
  20. ; or doing some high intensive CPU work.  Hint. Hint.
  21. ;
  22. ; Send me your protected mode source code!
  23. ; Send me your Objects!
  24. ; But most of all, Send me a postcard!!!!
  25. ;
  26. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  27.  
  28.             public _slidebytes       ; TRAN's slide byte routine
  29.             public _slidewords       ; slide word routine
  30.             public _fade_all         ; fade palette to a common colour
  31.             public _fade_palette     ; fade from esi to edi
  32.             public _palette1         ; temp storage palettes (768 bytes each)
  33.             public _palette2
  34.             public _sourcepal
  35.             public _destpal
  36.             public _fadestep
  37.             public _fadestatus
  38.             public _fade_palette_read; fade from current palette to pal at ESI
  39.             public _wait_for_fade    ; wait for irq fade to complete
  40.             public _get_palette      ; get palette from video card
  41.             public _put_palette      ; put palette to video card
  42.             public _default_palette  ; palette for DOS
  43.  
  44. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  45. ; Slide a block of bytes closer to another block in value
  46. ; In:
  47. ;   BL - max value to slide by (usually 1)
  48. ;   ECX - number of bytes to slide
  49. ;   ESI - block to slide towards
  50. ;   EDI - block to slide
  51. ; Out:
  52. ;   CF=1 - no changes made
  53. ;   CF=0 - at least one change made
  54. ; Notes: Routine courtesy of TRAN from HELL.EXE
  55. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  56.  
  57. _slidebytes:
  58.            pushad
  59.            xor bh,bh
  60. slidebytesml:
  61.            mov al,[edi]
  62.            mov ah,[esi]
  63.            cmp al,ah
  64.            je short slidebytesmlc
  65.            mov bh,1
  66.            jb short slidebytesmlf0
  67.            sub ah,al
  68.            neg ah
  69.            cmp ah,bl
  70.            jbe short slidebytesmlf2
  71.            mov ah,bl
  72. slidebytesmlf2:
  73.            neg ah
  74.            jmp short slidebytesmlf1
  75. slidebytesmlf0:
  76.            sub ah,al
  77.            cmp ah,bl
  78.            jbe short slidebytesmlf1
  79.            mov ah,bl
  80. slidebytesmlf1:
  81.            add al,ah
  82.            mov [edi],al
  83. slidebytesmlc:
  84.            inc edi
  85.            inc esi
  86.            loop slidebytesml
  87.            sub bh,1
  88.            popad
  89.            ret
  90.  
  91. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  92. ; Slide a block of words closer to another block in value
  93. ; In:
  94. ;   BX - max value to slide by (1 = really slow slide)
  95. ;   ECX - number of words to slide
  96. ;   ESI - block to slide towards
  97. ;   EDI - block to slide
  98. ; Out:
  99. ;   CF=1 - no changes made
  100. ;   CF=0 - at least one change made
  101. ; Notes: Idea courtesy of TRAN from _slidebytes
  102. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  103.  
  104. _slidewords:
  105.            pushad
  106.            xor dh,dh
  107. slidewordsml:
  108.            mov ax,[edi]
  109.            mov bp,[esi]
  110.            cmp ax,bp
  111.            je short slidewordsmlc
  112.            mov dh,1
  113.            jb short slidewordsmlf0
  114.            sub bp,ax
  115.            neg bp
  116.            cmp bp,bx
  117.            jbe short slidewordsmlf2
  118.            mov bp,bx
  119. slidewordsmlf2:
  120.            neg bp
  121.            jmp short slidewordsmlf1
  122. slidewordsmlf0:
  123.            sub bp,ax
  124.            cmp bp,bx
  125.            jbe short slidewordsmlf1
  126.            mov bp,bx
  127. slidewordsmlf1:
  128.            add ax,bp
  129.            mov [edi],ax
  130. slidewordsmlc:
  131.            add edi,2
  132.            add esi,2
  133.            loop slidewordsml
  134.            sub dh,1
  135.            popad
  136.            ret
  137.  
  138. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  139. ; Data for IRQ controlled palette fading routines
  140. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  141.  
  142. number_of_colours equ 256
  143.  
  144. _palette1   db number_of_colours*3 dup (0)
  145. _palette2   db number_of_colours*3 dup (0)
  146. _sourcepal  dd 0
  147. _destpal    dd 0
  148. _fadestep   dd 0
  149. _fadestatus db 0
  150. fadecount   db 0
  151.  
  152. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  153. ; _Fade_palette_read: IRQ Fade from current palette to new palette at ESI
  154. ; In:
  155. ;  ESI = palette to fade to
  156. ;   BH - how much to fade each pel        (usually 1)
  157. ;   BL - how often should fade be applied (255 = every IRQ)
  158. ; Out: null
  159. ; Notes: takes control of _irqcontrol2
  160. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  161.  
  162. _fade_palette_read:
  163.            mov _irqcontrol2,offset _ret ; just in case we are already doing a fade
  164.            mov _fadestep,ebx
  165.  
  166.            mov edi,offset _palette2 ; get current palette from card (yeah, i know its slow)
  167.            mov ecx,number_of_colours*3
  168.            xor al,al
  169.            call _get_palette
  170.  
  171.            mov edi,offset _palette2
  172.            jmp _fade_palette
  173.  
  174. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  175. ; _Fade_all: IRQ Fade palette to a common single colour
  176. ; In:
  177. ;  EAX = colour to fade to (xx,rd,gr,bl)
  178. ;   BH - how much to fade each pel
  179. ;   BL - how often should fade be applied (1 = very slow)
  180. ; Out: null
  181. ; Notes: takes control of _irqcontrol2
  182. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  183.  
  184. _fade_all:
  185.            mov _irqcontrol2,offset _ret ; just in case we are already doing a fade
  186.            mov _fadestep,ebx
  187.            mov ecx,number_of_colours
  188.            mov edi,offset _palette1
  189.            mov bl,al
  190.            shr eax,8
  191. fd_lp:
  192.            mov [edi+0],ah
  193.            mov [edi+1],al
  194.            mov [edi+2],bl
  195.            add edi,3
  196.            loop fd_lp
  197.  
  198.            mov edi,offset _palette2 ; get current palette from card (yeah, i know its slow)
  199.            mov ecx,number_of_colours*3
  200.            xor al,al
  201.            call _get_palette
  202.  
  203.            mov esi,offset _palette1
  204.            mov edi,offset _palette2
  205.            mov ebx,_fadestep
  206.  
  207. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  208. ; _Fade_palette: Fade palette from palette ESI to palette EDI
  209. ; In:
  210. ;  ESI - palette to fade to
  211. ;  EDI - palette to fade from
  212. ;   BH - how much to fade each pel
  213. ;   BL - how often should fade be applied (255 = every IRQ)
  214. ; Out: null
  215. ; Notes: takes control of _irqcontrol2
  216. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  217.  
  218. _fade_palette:
  219.            mov _irqcontrol2,offset _ret ; just in case we are already doing a fade
  220.  
  221.            mov _destpal,edi
  222.            mov edi,offset _palette1     ; copy palette to modify into buffer
  223.            mov _sourcepal,edi
  224.            mov _fadestep,ebx
  225.  
  226.            mov ecx,number_of_colours*3
  227.            rep movsb
  228.  
  229.            mov fadecount,0
  230.            mov _fadestatus,-1
  231.            mov _irqcontrol2,offset irqfade
  232.            ret
  233.  
  234. irqfade:
  235.            mov al,b _fadestep
  236.            add fadecount,al
  237.            jnc no_changeyet
  238.  
  239.            mov esi,_sourcepal
  240.            mov edi,_destpal
  241.            mov bl,b _fadestep+1
  242.            mov ecx,number_of_colours*3
  243.            call _slidebytes
  244.            jc no_more_fade
  245.  
  246.            cld
  247.            mov edx,dac_write_addr
  248.            xor al,al
  249.            out dx,al
  250.            mov esi,_destpal
  251.            inc edx
  252.            mov ecx,number_of_colours*3
  253.            rep outsb
  254.            ret
  255.  
  256. no_more_fade:
  257.            mov _irqcontrol2,offset _ret ; kill irq fade call
  258.            mov _fadestatus,0
  259. no_changeyet:
  260.            ret
  261.  
  262. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  263. ; Wait for fade to complete
  264. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  265.  
  266. _wait_for_fade:
  267.            test _fadestatus,-1     ; wait until fade is complete
  268.            jnz _wait_for_fade
  269.            ret
  270.  
  271. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  272. ; _GetPal - get current palette from video card
  273. ; In:
  274. ;   EDI - destination location
  275. ;    AL - start pel
  276. ;   ECX - number of pels to get (max 768)
  277. ; Out: ?
  278. ; Notes: Listen, I know this routine is duplicated in xmode.asm but I hate
  279. ;        stack frames.
  280. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  281.  
  282. _get_palette:
  283.            mov edx, dac_read_addr   ; read block of pals
  284.            out dx, al
  285.            mov edx, pel_data_reg
  286.  
  287.            rep insb                 ; block read dac registers
  288.            ret
  289.  
  290. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  291. ; _PutPal - put new palette to video card
  292. ; In:
  293. ;   ESI - destination location
  294. ;    AL - start pel
  295. ;   ECX - number of pels to write (max 768)
  296. ; Out: ?
  297. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  298.  
  299. _put_palette:
  300.            mov edx, dac_write_addr
  301.            out dx, al
  302.            mov edx, pel_data_reg
  303.  
  304.            rep outsb
  305.            ret
  306.  
  307. _default_palette label byte
  308.     db 000h,000h,000h,000h,000h,02Ah,000h,02Ah
  309.     db 000h,000h,02Ah,02Ah,02Ah,000h,000h,02Ah
  310.     db 000h,02Ah,02Ah,02Ah,000h,02Ah,02Ah,02Ah
  311.     db 000h,000h,015h,000h,000h,03Fh,000h,02Ah
  312.     db 015h,000h,02Ah,03Fh,02Ah,000h,015h,02Ah
  313.     db 000h,03Fh,02Ah,02Ah,015h,02Ah,02Ah,03Fh
  314.     db 000h,015h,000h,000h,015h,02Ah,000h,03Fh
  315.     db 000h,000h,03Fh,02Ah,02Ah,015h,000h,02Ah
  316.     db 015h,02Ah,02Ah,03Fh,000h,02Ah,03Fh,02Ah
  317.     db 000h,015h,015h,000h,015h,03Fh,000h,03Fh
  318.     db 015h,000h,03Fh,03Fh,02Ah,015h,015h,02Ah
  319.     db 015h,03Fh,02Ah,03Fh,015h,02Ah,03Fh,03Fh
  320.     db 015h,000h,000h,015h,000h,02Ah,015h,02Ah
  321.     db 000h,015h,02Ah,02Ah,03Fh,000h,000h,03Fh
  322.     db 000h,02Ah,03Fh,02Ah,000h,03Fh,02Ah,02Ah
  323.     db 015h,000h,015h,015h,000h,03Fh,015h,02Ah
  324.     db 015h,015h,02Ah,03Fh,03Fh,000h,015h,03Fh
  325.     db 000h,03Fh,03Fh,02Ah,015h,03Fh,02Ah,03Fh
  326.     db 015h,015h,000h,015h,015h,02Ah,015h,03Fh
  327.     db 000h,015h,03Fh,02Ah,03Fh,015h,000h,03Fh
  328.     db 015h,02Ah,03Fh,03Fh,000h,03Fh,03Fh,02Ah
  329.     db 015h,015h,015h,015h,015h,03Fh,015h,03Fh
  330.     db 015h,015h,03Fh,03Fh,03Fh,015h,015h,03Fh
  331.     db 015h,03Fh,03Fh,03Fh,015h,03Fh,03Fh,03Fh
  332.     db 000h,026h,010h,012h,003h,015h,018h,000h
  333.     db 000h,000h,00Ah,002h,026h,025h,00Fh,000h
  334.     db 001h,02Ah,004h,026h,009h,015h,030h,000h
  335.     db 000h,000h,026h,023h,020h,000h,000h,000h
  336.     db 006h,005h,029h,000h,000h,000h,009h,030h
  337.     db 021h,00Dh,033h,01Ah,026h,018h,003h,030h
  338.     db 031h,032h,033h,034h,035h,036h,037h,038h
  339.     db 039h,001h,002h,003h,004h,005h,006h,010h
  340.     db 013h,011h,012h,017h,03Bh,001h,028h,001h
  341.     db 000h,00Bh,010h,039h,008h,000h,000h,000h
  342.     db 034h,00Fh,001h,002h,004h,00Ah,002h,024h
  343.     db 00Fh,017h,026h,02Bh,022h,034h,01Fh,01Ah
  344.     db 019h,01Bh,018h,003h,03Fh,000h,000h,00Ah
  345.     db 000h,02Bh,03Dh,018h,000h,000h,000h,039h
  346.     db 000h,00Eh,000h,000h,033h,000h,033h,02Bh
  347.     db 003h,013h,025h,02Eh,024h,020h,02Dh,025h
  348.     db 020h,021h,020h,030h,02Fh,033h,034h,023h
  349.     db 021h,032h,024h,021h,00Dh,00Ah,00Dh,00Ah
  350.     db 00Ah,02Fh,028h,02Eh,020h,00Dh,023h,003h
  351.     db 021h,032h,034h,028h,039h,020h,034h,032h
  352.     db 029h,025h,033h,020h,034h,02Fh,020h,022h
  353.     db 025h,020h,021h,020h,032h,025h,027h,035h
  354.     db 02Ch,021h,032h,020h,02Fh,02Eh,020h,004h
  355.     db 029h,027h,029h,034h,021h,02Ch,020h,010h
  356.     db 029h,038h,025h,02Ch,03Ah,020h,028h,034h
  357.     db 031h,036h,029h,020h,032h,039h,038h,02Dh
  358.     db 031h,034h,038h,037h,00Dh,00Ah,020h,020h
  359.     db 020h,020h,020h,020h,020h,020h,020h,020h
  360.     db 020h,020h,020h,020h,020h,020h,020h,020h
  361.     db 020h,020h,020h,020h,020h,020h,020h,020h
  362.     db 020h,021h,02Eh,024h,020h,02Fh,02Eh,020h
  363.     db 034h,028h,025h,020h,014h,02Fh,032h,02Fh
  364.     db 02Eh,034h,02Fh,020h,016h,012h,020h,013h
  365.     db 009h,007h,03Ah,020h,028h,034h,031h,036h
  366.     db 029h,020h,036h,033h,031h,02Dh,036h,036h
  367.     db 032h,035h,00Dh,00Ah,00Dh,00Ah,00Fh,032h
  368.     db 020h,037h,032h,029h,034h,025h,020h,034h
  369.     db 02Fh,020h,034h,028h,029h,033h,020h,021h
  370.     db 024h,024h,032h,025h,033h,033h,03Ah,00Dh
  371.     db 00Ah,00Dh,00Ah,020h,020h,020h,020h,00Ah
  372.     db 02Fh,028h,02Eh,020h,00Dh,023h,003h,021h
  373.     db 032h,034h,028h,039h,00Dh,00Ah,020h,020h
  374.     db 020h,020h,031h,033h,031h,036h,020h,012h
  375.     db 025h,024h,037h,02Fh,02Fh,024h,020h,00Ch
  376.     db 021h,02Eh,025h,00Dh,00Ah,020h,020h,020h
  377.     db 020h,010h,029h,023h,02Bh,025h,032h,029h
  378.     db 02Eh,027h,02Ch,020h,00Fh,02Eh,034h,021h
  379.     db 032h,029h,02Fh,02Eh,00Dh,00Ah,020h,020h
  380.     db 020h,020h,003h,021h,02Eh,021h,024h,021h
  381.     db 02Ch,020h,005h,021h,032h,034h,028h,02Ch
  382.     db 020h,00Dh,029h,02Ch,02Bh,039h,020h,017h
  383.     db 021h,039h,02Eh,020h,020h,028h,026h,02Fh
  384.     db 032h,020h,034h,028h,02Fh,033h,025h,020h
  385.     db 02Fh,035h,034h,02Dh,02Fh,026h,02Dh,034h
  386.     db 02Fh,037h,02Eh,025h,032h,033h,029h,00Dh
  387.     db 00Ah,020h,020h,020h,020h,00Ch,031h,018h
  388.     db 020h,031h,003h,035h,00Dh,00Ah,024h,03Eh
  389.     db 000h,000h,000h,000h,03Fh,001h,00Fh,001h
  390.     db 030h,000h,039h,003h,000h,003h,000h,03Ch
  391.     db 001h,00Ch,001h,030h,000h,01Ch,000h,03Ch
  392.     db 00Eh,000h,004h,000h,031h,001h,037h,001h
  393.     db 030h,000h,03Dh,010h,000h,006h,000h,02Fh
  394.     db 001h,035h,001h,000h,000h,000h,03Fh,023h
  395.     db 000h,00Dh,000h,00Eh,033h,004h,020h,016h
  396.     db 025h,023h,034h,02Fh,032h,033h,020h,029h
  397.     db 02Eh,020h,033h,032h,030h,038h,034h,030h
  398.     db 030h,020h,00Dh,02Fh,024h,025h,02Dh,018h
  399.     db 03Bh,03Fh,00Fh,000h,030h,001h,00Eh,016h
  400.     db 025h,023h,034h,02Fh,032h,020h,012h,02Fh
  401.     db 035h,034h,029h,02Eh,025h,033h,020h,022h
  402.     db 039h,020h,00Ah,02Fh,028h,02Eh,020h,00Dh
  403.     db 023h,003h,021h,032h,034h,028h,039h,03Fh
  404.  
  405.